
#include "HeaderFiles.h"
#include "serialHMI_ex_api.h"
#include "power_ctrl.h"
#include "BMS_can_msg.h"
#include "offline_param.h"
#include "fault_analyse.h"
#include "clean_can_msg.h"
#include "robot_interact.h"

/*!
    \brief      
    \param[in]  none
    \param[out] none
    \retval     none
*/

void hmi_datalist_update(STR_HMI_HANDLE* hmiHdl, uint16_t length)
{
	
	#if 0  // hmi comm data test
	
	static uint16_t data_cnt = 0;
	
	for(uint8_t i=0; i<length; i++)
	{
		hmiHdl->monitor_data[i] = 0x8000 + data_cnt++;
	}
	
	hmiHdl->monitor_fault_now = 0xFFFFFFFF;
	hmiHdl->monitor_fault_his = 0xFFFFFFFF;
	
	#else  // hmi datalist update with project var
	
	hmiHdl->monitor_data[0]   = 0x8000 + hmiHdl->monitor_heartbeat;
	hmiHdl->monitor_data[1]   = 0x8000 + SOFTWARE_VERSION;
	
	hmiHdl->monitor_data[2]   = 0x8000 + chargeCtrl.FSM;
	hmiHdl->monitor_data[3]   = 0x8000 + (uint16_t)chargeCtrl.charge_time_s;
	hmiHdl->monitor_data[4]   = 0x8000 + userHdl.signal.real.vdc_charge * 10.0f;
	hmiHdl->monitor_data[5]   = 0x8000 + userHdl.signal.real.vdc_plate * 10.0f;
	
	hmiHdl->monitor_data[6]   = 0x8000 + userHdl.ctrl.charge_relay;
	
	hmiHdl->monitor_data[7]   = 0x8000 + userHdl.signal.charge_status;
	hmiHdl->monitor_data[8]   = 0x8000 + userHdl.signal.limit_X1;
	hmiHdl->monitor_data[9]   = 0x8000 + userHdl.signal.limit_X2;
	
	hmiHdl->monitor_data[10]  = 0x8000 + userHdl.ctrl.en_waste_pump;
	hmiHdl->monitor_data[11]  = 0x8000 + userHdl.ctrl.en_actuate_X1;
	hmiHdl->monitor_data[12]  = 0x8000 + userHdl.ctrl.en_actuate_X2;
	
	hmiHdl->monitor_data[13]  = 0x8000 + userHdl.ctrl.en_buzzer_x1;

	hmiHdl->monitor_data[14]  = 0x8000 + userHdl.ctrl.type_LED_left;
	hmiHdl->monitor_data[15]  = 0x8000 + userHdl.ctrl.type_LED_right;

	hmiHdl->monitor_data[16]  = 0x8000 + userHdl.signal.real.temp_x1;
	hmiHdl->monitor_data[17]  = 0x8000 + userHdl.signal.real.temp_x2;

	hmiHdl->monitor_data[18]  = 0x8000 + userHdl.signal.real.level_X1;
	hmiHdl->monitor_data[19]  = 0x8000 + userHdl.signal.real.level_X2;
	hmiHdl->monitor_data[20]  = 0x8000 + userHdl.signal.real.water_X1;
	hmiHdl->monitor_data[21]  = 0x8000 + userHdl.signal.real.water_X2;

	hmiHdl->monitor_data[22]  = 0x8000 + robot_hdl.ID_station;
	hmiHdl->monitor_data[23]  = 0x8000 + robot_hdl.pair_status;
	hmiHdl->monitor_data[24]  = 0x8000 + robot_hdl.pair.ID_robot;
	hmiHdl->monitor_data[25]  = 0x8000 + robot_hdl.pair.charge_time;
	hmiHdl->monitor_data[26]  = 0x8000 + robot_hdl.overtime_flg;
	hmiHdl->monitor_data[27]  = 0x8000 + robot_hdl.pair.bat_soc;
	hmiHdl->monitor_data[28]  = 0x8000 + robot_hdl.pair.pair_status;
	hmiHdl->monitor_data[29]  = 0x8000 + 0;
	
	hmiHdl->monitor_fault_now = faultCode.all;
	hmiHdl->monitor_fault_his = 0;
	
	#endif
}


/*!
    \brief      
    \param[in]  none
    \param[out] none
    \retval     none
*/

void hmi_paramlist_update(uint16_t* param_temp, uint16_t length)
{
	#if 0  // HMI param read all test data

	static uint16_t test_data = 0;
	
	for(uint16_t i=0; i<length; i++)
	{
		param_temp[i] = test_data++;
	}
	
	#else
	
	for(uint16_t i=0; i<length; i++)
	{
		param_temp[i] = AppParamHdl.data[i];
	}
	
	#endif
	
	
}

/*!
    \brief      
    \param[in]  none
    \param[out] none
    \retval     none
*/

void hmi_product_info_update(uint16_t* info_temp, uint16_t length)
{
		
	#if 1  // HMI product information read test data

	static uint16_t test_data = 0;
	
	for(uint16_t i=0; i<length; i++)
	{
		info_temp[i] = test_data++;
	}
	
	#else

	
	#endif
	
	
}



/*!
    \brief      
    \param[in]  none
    \param[out] none
    \retval     none
*/







/*!
    \brief      
    \param[in]  none
    \param[out] none
    \retval     none
*/

uint8_t hmi_param_write_handle(uint16_t addr, uint16_t data)
{
	uint8_t write_res = 0;
	
	
	#if 0  // HMI hmi parameter write test
	
	if(data == 100)	write_res = 0;
	else     		write_res = 1;
	
	#else
	
	write_res = flash_param_cache_write(addr, data);
	
	#endif
	

	return write_res;
}



/*!
    \brief      
    \param[in]  none
    \param[out] none
    \retval     none
*/

uint8_t hmi_param_save_handle(void)
{
	uint8_t save_res = 0;
	
	save_res = flash_param_saveALL();
	
	return save_res;
}




/*!
    \brief      
    \param[in]  none
    \param[out] none
    \retval     none
*/

uint8_t hmi_ota_reset_handle(void)
{
	uint8_t res_flg;
	
	#if 0
	if((userHdl.signal.limit_X2 == 0) && (userHdl.signal.limit_X1 == 1))
	#endif
	
	{
		NVIC_SystemReset();
		res_flg = 1;		
	}	
	
	return res_flg;
}








